﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Model;
using Utility;
namespace Service
{
    /// <summary>
    /// 功能：HW_OrgDetail类数据访问
    /// 创建人：Wilson
    /// 创建时间：2013-1-30   
    /// </summary>
    public class HW_OrgDetailService : IDisposable
    {
        #region 公共
        private System.ComponentModel.Component component = new System.ComponentModel.Component();

        private bool disposed = false;

        ~HW_OrgDetailService()
        {
            Dispose(false);
        }

        #endregion

        #region IDisposable 成员

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!this.disposed)
            {

                if (disposing)
                {

                    component.Dispose();
                }

                disposed = true;

            }
        }
        #endregion
		#region##MapperHW_OrgDetail
        public IList<HW_OrgDetail> MapperList(SqlDataReader reader)
         {
            IList<HW_OrgDetail> list = new List<HW_OrgDetail>();
            HW_OrgDetail obj=null;
            while (reader.Read())
            {
                obj = new HW_OrgDetail();
                obj.OrgCode = (string)reader["OrgCode"];
                obj.Address = reader["Address"] as string;
                obj.Email = reader["Email"] as string;
                obj.MobilePhone = reader["MobilePhone"] as string;
                obj.OfficePhone = reader["OfficePhone"] as string;
                obj.ZipCode = reader["ZipCode"] as string;
                obj.Version = (int)reader["Version"];
                obj.Fax = reader["Fax"] as string;
                obj.LinkMan = reader["LinkMan"] as string;
                list.Add(obj);
            }
            return list;
         }
        public HW_OrgDetail Mapper(SqlDataReader reader)
         {
            HW_OrgDetail obj=null;
            if (reader.Read())
            {
                obj = new HW_OrgDetail();
                obj.OrgCode = (string)reader["OrgCode"];
                obj.Address = reader["Address"] as string;
                obj.Email = reader["Email"] as string;
                obj.MobilePhone = reader["MobilePhone"] as string;
                obj.OfficePhone = reader["OfficePhone"] as string;
                obj.ZipCode = reader["ZipCode"] as string;
                obj.Version = (int)reader["Version"];
                obj.Fax = reader["Fax"] as string;
                obj.LinkMan = reader["LinkMan"] as string;
            }
            return obj;
         }
        #endregion
        #region##通过主键ID得到HW_OrgDetail
        /// <summary>
        /// 功能：通过ID得到HW_OrgDetail
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
        public HW_OrgDetail GetById(string orgcode)
        {            
            string sql = "select * from HW_OrgDetail where OrgCode = @PK";
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@PK",orgcode)
            };
            
            SqlDataReader reader=SqlHelper.ExecuteReader(WebConn.connString,CommandType.Text,sql,sp);
            return Mapper(reader);
        }
        #endregion
		
		#region##通过主键ID删除HW_OrgDetail
        /// <summary>
        /// 功能：通过主键ID删除HW_OrgDetail
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
		public int DeleteById(string orgcode)
		{
			int i = 0;
			string sql = "delete from HW_OrgDetail where OrgCode = @PK";
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@PK",50)
            };
            i= SqlHelper.ExecuteNonQuery(WebConn.connString,CommandType.Text,sql,sp);
			return i;
		}
        /// <summary>
        /// 功能：通过主键ID删除HW_OrgDetail
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
		public int DeleteById(SqlTransaction transaction,string orgcode)
		{
			int i = 0;
			string sql = "delete from HW_OrgDetail where OrgCode = @PK";
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@PK",orgcode)
            };
            i= SqlHelper.ExecuteNonQuery(transaction,CommandType.Text,sql,sp);
			return i;
		}
		#endregion			
		
        #region##添加HW_OrgDetail
        /// <summary>
        /// 功能：添加HW_OrgDetail
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int Add(HW_OrgDetail hw_orgdetail)
        {
            int result = 0;
            string sql = "insert into HW_OrgDetail(OrgCode,Address,Email,MobilePhone,OfficePhone,ZipCode,Version,Fax,LinkMan) values(@OrgCode,@Address,@Email,@MobilePhone,@OfficePhone,@ZipCode,@Version,@Fax,@LinkMan)";			
            SqlParameter[] sp = new SqlParameter[]
            {
				new SqlParameter("@OrgCode",hw_orgdetail.OrgCode),
				new SqlParameter("@Address",hw_orgdetail.Address),
				new SqlParameter("@Email",hw_orgdetail.Email),
				new SqlParameter("@MobilePhone",hw_orgdetail.MobilePhone),
				new SqlParameter("@OfficePhone",hw_orgdetail.OfficePhone),
				new SqlParameter("@ZipCode",hw_orgdetail.ZipCode),
				new SqlParameter("@Version",hw_orgdetail.Version),
				new SqlParameter("@Fax",hw_orgdetail.Fax),
				new SqlParameter("@LinkMan",hw_orgdetail.LinkMan)
            };
            result = SqlHelper.ExecuteNonQuery(WebConn.connString,CommandType.Text,sql,sp);
            return result;
        }
         /// <summary>
        /// 功能：添加HW_OrgDetail
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int Add(SqlTransaction transaction,HW_OrgDetail hw_orgdetail)
        {
            int result = 0;
            string sql = "insert into HW_OrgDetail(OrgCode,Address,Email,MobilePhone,OfficePhone,ZipCode,Version,Fax,LinkMan) values(@OrgCode,@Address,@Email,@MobilePhone,@OfficePhone,@ZipCode,@Version,@Fax,@LinkMan)";			
            SqlParameter[] sp = new SqlParameter[]
            {
				new SqlParameter("@OrgCode",hw_orgdetail.OrgCode),
				new SqlParameter("@Address",hw_orgdetail.Address),
				new SqlParameter("@Email",hw_orgdetail.Email),
				new SqlParameter("@MobilePhone",hw_orgdetail.MobilePhone),
				new SqlParameter("@OfficePhone",hw_orgdetail.OfficePhone),
				new SqlParameter("@ZipCode",hw_orgdetail.ZipCode),
				new SqlParameter("@Version",hw_orgdetail.Version),
				new SqlParameter("@Fax",hw_orgdetail.Fax),
				new SqlParameter("@LinkMan",hw_orgdetail.LinkMan)
            };
            result = SqlHelper.ExecuteNonQuery(transaction,CommandType.Text,sql,sp);
            return result;
        }
        #endregion
		
		#region##得到HW_OrgDetail集合
		/// <summary>
        /// 功能：得到HW_OrgDetail集合
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>       
        /// <returns></returns>
		public IList<HW_OrgDetail> GetList()
		{
			string sql = "select * from HW_OrgDetail";			
			SqlDataReader reader = SqlHelper.ExecuteReader(WebConn.connString,CommandType.Text,sql);
            return MapperList(reader);
		}
		#endregion
		
		#region##修改HW_OrgDetail
        /// <summary>
        /// 功能：修改HW_OrgDetail
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int ModHW_OrgDetail(HW_OrgDetail hw_orgdetail)
        {
            int result = 0;
            string sql = "update HW_OrgDetail set OrgCode = @OrgCode,Address = @Address,Email = @Email,MobilePhone = @MobilePhone,OfficePhone = @OfficePhone,ZipCode = @ZipCode,Version = @Version,Fax = @Fax,LinkMan = @LinkMan where OrgCode = @OrgCode";
            SqlParameter[] sp = new SqlParameter[]
            {       
				new SqlParameter("@OrgCode",hw_orgdetail.OrgCode),
				new SqlParameter("@Address",hw_orgdetail.Address),
				new SqlParameter("@Email",hw_orgdetail.Email),
				new SqlParameter("@MobilePhone",hw_orgdetail.MobilePhone),
				new SqlParameter("@OfficePhone",hw_orgdetail.OfficePhone),
				new SqlParameter("@ZipCode",hw_orgdetail.ZipCode),
				new SqlParameter("@Version",hw_orgdetail.Version),
				new SqlParameter("@Fax",hw_orgdetail.Fax),
				new SqlParameter("@LinkMan",hw_orgdetail.LinkMan)
            };
            result = SqlHelper.ExecuteNonQuery(WebConn.connString,CommandType.Text,sql,sp);
            return result;
        }
         /// <summary>
        /// 功能：修改HW_OrgDetail
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int ModHW_OrgDetail(SqlTransaction transaction,HW_OrgDetail hw_orgdetail)
        {
            int result = 0;
            string sql = "update HW_OrgDetail set OrgCode = @OrgCode,Address = @Address,Email = @Email,MobilePhone = @MobilePhone,OfficePhone = @OfficePhone,ZipCode = @ZipCode,Version = @Version,Fax = @Fax,LinkMan = @LinkMan where OrgCode = @OrgCode";
            SqlParameter[] sp = new SqlParameter[]
            {       
				new SqlParameter("@OrgCode",hw_orgdetail.OrgCode),
				new SqlParameter("@Address",hw_orgdetail.Address),
				new SqlParameter("@Email",hw_orgdetail.Email),
				new SqlParameter("@MobilePhone",hw_orgdetail.MobilePhone),
				new SqlParameter("@OfficePhone",hw_orgdetail.OfficePhone),
				new SqlParameter("@ZipCode",hw_orgdetail.ZipCode),
				new SqlParameter("@Version",hw_orgdetail.Version),
				new SqlParameter("@Fax",hw_orgdetail.Fax),
				new SqlParameter("@LinkMan",hw_orgdetail.LinkMan)
            };
            result = SqlHelper.ExecuteNonQuery(transaction,CommandType.Text,sql,sp);
            return result;
        }
        #endregion
		
		#region##统计HW_OrgDetail
		/// <summary>
        /// 修改HW_OrgDetail
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
		public int SelectCount()
		{
			int i = 0;
            string sql = "select count(*) from HW_OrgDetail";
            i = (int)SqlHelper.ExecuteScalar(WebConn.connString,CommandType.Text,sql);
            return i;
		}
		/// <summary>
        /// 修改HW_OrgDetail
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int SelectCountById()
        {
            int i=0;
            string sql="select count(OrgCode) from HW_OrgDetail";
            i = (int)SqlHelper.ExecuteScalar(WebConn.connString,CommandType.Text,sql);
            return i;
        }
		#endregion
        #region##自定义HW_OrgDetail
        #endregion
                
    }
}
